<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2018/11/14
 * Time: 13:54
 */

namespace app\modules\simpleFactory\controller;

use app\modules\simpleFactory\SimpleFactory;
use yii\web\Controller;

class DefaultController extends Controller
{
    /**
     * 简单工厂模式示例
     * 简单工厂模式是一个精简版的工厂模式。
     * 它与静态工厂模式最大的区别是它不是『静态』的。因为非静态，所以你可以拥有多个不同参数的工厂，你可以为其创建子类。甚至可以模拟（Mock）池
     *
     * @date   2018/11/14
     * @author edmmss
     * @return bool
     */
    public function actionIndex()
    {
        $simpleFactory = new SimpleFactory();
        $bicycle = $simpleFactory->createBicycle();
        $car = $simpleFactory->createCar();

        var_dump($bicycle);
        var_dump($car);
        var_dump($bicycle->driveTo('大草原'));
        var_dump($car->driveTo('海南'));

        return true;
    }
}